import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains # 鼠标事件

# 前置准备
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
driver.implicitly_wait(15)

# 鼠标悬浮
set_btn = driver.find_element(By.ID,"s-usersetting-top")  #   定位到设置
ActionChains(driver).move_to_element(set_btn).perform()

# 定位搜索设置
driver.find_elements(By.CLASS_NAME,"set")[0].click()
time.sleep(2)
# 点击保存设置
driver.find_element(By.CLASS_NAME,"prefpanelgo").click()
time.sleep(2)
# 捕捉弹窗
alert = driver.switch_to.alert
alert.accept() # 点击弹窗中的确定

# alert.dismiss() # 点击弹窗中的取消

time.sleep(5)



